package org.ucas.kgraph.entity;

public enum RelationType  {
  Parent(0,"Parent"),
  Link(1,"Related");

  public final Integer id;

  public final String name;

  RelationType(int id, String name) {
    this.id = id;
    this.name = name;
  }

  public static RelationType valueOf(int id){
    switch (id){
      case 0:
        return Parent;
      case 1:
        return Link;
      default:
        throw new IllegalArgumentException("Unknown Relation Type!");
    }
  }

  public static RelationType forName(String name){
    for (RelationType t : values())
      if (t.name.equals(name))
        return t;
    throw new IllegalArgumentException("Invalid relation type name " + name);
  }



  /**
   * 判断连接是否是无向的
   * @param category
   * @return
   */
  public static boolean unDirected(RelationType category){
    switch (category){
      case Parent:
        return false;
      case Link:
        return true;
      default:
        return false;
    }
  }




  @Override
  public String toString() {
    return name;
  }

  /**
   * 获取被持久化字段的值
   *
   * @return 被持久化字段的值
   */
  public String getPersistedValue(){return id.toString();}

  /**
   * 由被持久化的字段的值获取枚举类型
   *
   * @return
   */
  public RelationType returnEnum(String id){return valueOf(Integer.valueOf(id));}


}
